package leetcode

type ListNode struct {
	Val  int
	Next *ListNode
}

func removeNthFromEnd(head *ListNode, n int) *ListNode {
	resHead := ListNode{0, head}
	leftPtr, rightPtr := &resHead, &resHead
	for i := 0; i <= n; i++ {
		rightPtr = rightPtr.Next
	}
	for rightPtr != nil {
		leftPtr = leftPtr.Next
		rightPtr = rightPtr.Next
	}
	leftPtr.Next = leftPtr.Next.Next
	return resHead.Next
}
